<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="zh-cn">
<head>


	<!-- Bootstrap -->
	<include file="Include/css" />
	<title>卖家中心-首页</title>
	<link href="__STATICS__/css/index.css" rel="stylesheet">
        <link href="__STATICS__/css/sweet-alert.css" rel="stylesheet">
        <script type="text/javascript" src="__STATICS__/js/sweet-alert.min.js"></script>
    <style>
        .edit_fushu
        {
            display: block;
        }
        .margin10
        {
            margin:10px;
        }
        .spec_button_wraper
        {
            width:135px;
        }
    </style>

</head>
<body>
<include file="Include/nav_top" />
<div class="container clearfix" id="left_menu_wraper" >
	<include  file="Include/menu_left" />
		<div id="right-content">
			<div id="right-content-inner">
				<ul class="breadcrumb">
					<span>您的位置：</span>
					<li><a href="index.php">首页</a> </li>
					<li class="">商家管理</li>
					<li class="active">商家信息</li>
				</ul>

            <div role="tabpanel">
                <div class="back pull-right clearfix">
                    <a class="btn btn-default" href="javascript:history.back();">
                        <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span> 后退
                    </a>     
                                       
                </div>
                <div class="back pull-right clearfix">
                     <a href="javascript:void(0);" class="btn btn-primary" id="save_msg" >保存</a>&nbsp;&nbsp;
                 </div>
                        <!-- Tab panes -->
                        <div class="tab-content">
                            <div role="tabpanel" class="tab-pane active" id="home">

                                    
                                        <div class="row clearfix">
<!--                                            <div class="col-md-12 margin10">
                                                <div class="col-md-2 text_right form_bar">
                                                                商店帐号：
                                                </div>
                                                <div class="col-md-4">
                                                    <input id="shopAccount" value="{$arr.shopAccount}" type="text" class="form-control"/>
                                                </div>
                                                <div class="col-md-1 text_warning text_left form_bar">
                                                                *
                                                </div>
                                            </div>
                                            <div class="col-md-12 margin10">
                                                    <div class="col-md-2 text_right form_bar">
                                                            初始密码：
                                                    </div>
                                                    <div class="col-md-4">
                                                        <input id="shopPassword"  type="password" class="form-control"/>
                                                    </div>
                                                    <div class="col-md-1 text_warning text_left form_bar">
                                                            *
                                                    </div>
                                            </div>
                                            <div class="col-md-12 margin10">
                                                    <div class="col-md-2 text_right form_bar">
                                                            确认密码：
                                                    </div>
                                                    <div class="col-md-4">
                                                        <input id="rePassword"  type="password" class="form-control"/>
                                                    </div>
                                                    <div class="col-md-1 text_warning text_left form_bar">
                                                            *
                                                    </div>
                                            </div>-->
                                            <div class="col-md-12 margin10">
                                                    <div class="col-md-2 text_right form_bar">
                                                            商家名称：
                                                    </div>
                                                    <div class="col-md-4">
                                                        <input id="shopName" value="{$arr.shopName}" type="text" class="form-control"/>
                                                    </div>
                                                    <div class="col-md-4 text_warning text_left form_bar">
                                                            * 最大长度12个字符
                                                    </div>
                                            </div>
                                            <div class="col-md-12 margin10">
                                                    <div class="col-md-2 text_right form_bar">
                                                            商家类型：
                                                    </div>
                                                    <div class="col-md-4">
                                                       <select  id="shopType" class="form-control">
                                                           <option value="1" 
                                                                   <eq name="arr['shopType']" value="1" >selected</eq>
                                                                   >加油站</option>
                                                           <option value="2" 
                                                                   <eq name="arr['shopType']" value="2" >selected</eq>
                                                                   >洗车场</option>
                                                           <option value="3" 
                                                                   <eq name="arr['shopType']" value="3" >selected</eq>
                                                                   >自营店</option>
                                                        </select>
                                                    </div>
                                                    <div class="col-md-1 text_warning text_left form_bar">
                                                            *
                                                    </div>
                                            </div>
                                            <div id="oil_div" class="col-md-12 margin10" <gt name="arr['shopType']" value="1" >style="display:none;"</gt> >
                                                    <div class="col-md-2 text_right form_bar">
                                                            油单价：
                                                    </div>
                                                    <div class="col-md-9">
                                                    
                                                    
                                                       <volist name='oilPrice' id='vo'>
                                                       <div class="col-xs-4 addOilList">
	                                                       <div class="panel panel-default">
		                                                       <div class="panel-heading clearfix">
		                                                       		<a href="javascript:void(0);" class="pull-right text-left text-danger deleteOilPro">
		                                                       			<i class="glyphicon glyphicon-trash "></i>
		                                                       		</a>
		                                                       </div>
		                                                       <div class="panel-body">
			                                                       <form>
				                                                       <div class="form-group">
				                                                       		<label for="proName" class="control-label">品名:</label>
				                                                       		<input type="text" class="form-control oilNameInput" placeholder="品名" value='{$vo.name}'>
				                                                       </div>
				                                                       <div class="form-group">
				                                                       		<label for="proPrice" class="control-label">价格:</label>
					                                                       	<div class="input-group">
					                                                       		<input value="{$vo.price}" type="text" placeholder="价格" class="form-control oilPriceInput">
					                                                       		<div class="input-group-addon">元</div>
				                                                       		</div>
				                                                       </div>
			                                                       </form>
		                                                       </div>
	                                                       </div>
                                                       </div>
														</volist>
                                                        
                                                        
                                                        
                                                        <div class="col-xs-4">
                                                            <button class="btn btn-info" id="addOilBtn"><i class="glyphicon glyphicon-plus"></i> 添加油单价</button>
                                                        </div>

                                                    </div>
                                                    <div class="col-md-1 text_warning text_left form_bar">
                                                            *
                                                    </div>
                                            </div>
                                            <div class="col-md-12 margin10">
                                                    <div class="col-md-2 text_right form_bar">
                                                            可否使用汇通卡：
                                                    </div>
                                                    <div class="col-md-4">
                                                       <!--<div class="col-md-12 margin10">-->
                                                            <div class="btn-group clearfix" data-toggle="buttons">
                                                                <label class="btn btn-warning <eq name="arr['allowCard']" value="1" >active</eq>" >
                                                                    <input name="allowCard" type="radio" id="allow_1" autocomplete="off" value="1"
                                                                           <eq name="arr['allowCard']" value="1" >checked</eq>
                                                                           > ON
                                                                </label>
                                                                <label class="btn btn-warning <eq name="arr['allowCard']" value="0" >active</eq>">
                                                                    <input name="allowCard" type="radio" id="allow_0" autocomplete="off" value="0"
                                                                           <eq name="arr['allowCard']" value="0" >checked</eq>
                                                                           > OFF
                                                                </label>
                                                            </div>
                                                        <!--</div>-->
                                                    </div>
                                                    <div class="col-md-1 text_warning text_left form_bar">
                                                            *
                                                    </div>
                                            </div>
                                            <div class="col-md-12 margin10">
                                                    <div class="col-md-2 text_right form_bar">
                                                            商家是否营业：
                                                    </div>
                                                    <div class="col-md-4">
                                                       <!--<div class="col-md-12 margin10">-->
                                                            <div class="btn-group clearfix" data-toggle="buttons">
                                                                <label class="btn btn-warning <eq name="arr['isWork']" value="1" >active</eq>" >
                                                                    <input name="isWork" type="radio" id="work_1" autocomplete="off" value="1"
                                                                           <eq name="arr['isWork']" value="1" >checked</eq>
                                                                           > ON
                                                                </label>
                                                                <label class="btn btn-warning <eq name="arr['isWork']" value="0" >active</eq>">
                                                                    <input name="isWork" type="radio" id="work_0" autocomplete="off" value="0"
                                                                           <eq name="arr['isWork']" value="0" >checked</eq>
                                                                           > OFF
                                                                </label>
                                                            </div>
                                                        <!--</div>-->
                                                    </div>
                                                    <div class="col-md-1 text_warning text_left form_bar">
                                                            *
                                                    </div>
                                            </div>
                                            
                                       <div class="col-md-12 margin10" >
                                            <div class="col-md-2 text_right form_bar">
                                                省市区：
                                            </div>
                                            <div class="col-md-8 select_wraper">
                                                <div class="col-md-3">
                                                    <select  id="s_province" class="form-control">

                                                    </select>
                                                </div>

                                                <div class="col-md-3">
                                                        <select  id="s_city" class="form-control">

                                                        </select>
                                                </div>

                                                <div class="col-md-3">
                                                        <select id="s_county" class="form-control">

                                                        </select>
                                                </div>

                                            </div>

                                        </div>
                                        <div class="col-md-12 margin10">
                                                <div class="col-md-2 text_right form_bar">
                                                        详细地址：
                                                </div>
                                                <div class="col-md-4">
                                                        <input id="address" value="{$arr.address}" type="text" class="form-control"/>
                                                </div>
                                                <div class="col-md-1 text_warning text_left form_bar">
                                                        *
                                                </div>
                                        </div>
                                        <div class="col-md-12 margin10">
                                                <div class="col-md-2 text_right form_bar">
                                                        描述：
                                                </div>
                                                <div class="col-md-4">
                                                    <textarea id="desc" class="form-control">{$arr.desc} </textarea>
                                                </div>
                                        </div>
                                            
                                            <div class="col-md-12 margin10" >
                                                <div class="col-md-2 text_right form_bar">
                                                        上传图片：
                                                </div>
                                                <div class="col-md-4">
                                                    <div class=" padding0 margin10">
                                                        <div class="upload_wraper dash">
                                                            <div class="logo_wraper ">
                                                                <img id="pic"  src="{$imgDomain}/{$showPic}" 
                                                                     class="width100 img-rounded" alt="">
                                                                <input type="file" class="input_file" id="fileupload" name="file" value="" data-url="" multiple="">
                                                            </div>

                                                        </div>
                                                    </div>
                                                </div>                                                                                             

                                            </div>

                                <div class="col-md-12 margin10" >
                                        <div class="col-md-2 text_right form_bar">
                                                经度：
                                        </div>
                                        <div class="col-md-4">
                                            <input type="text" value="{$arr.x}" placeholder="点击地图以确定" id="txt_lng" class="form-control"/>
                                        </div>

                                </div>
                                <div class="col-md-12 margin10" >
                                        <div class="col-md-2 text_right form_bar">
                                                纬度：
                                        </div>
                                        <div class="col-md-4">
                                            <input type="text"  value="{$arr.y}" placeholder="点击地图以确定" id="txt_lat" class="form-control"/>
                                        </div>

                                </div>
                                
                                        <div class="col-md-12 margin10" >
                                                <div class="col-md-2 text_right form_bar">
                                                        <!--地址查找：-->&nbsp;
                                                </div>
                                                <div class="col-md-4">
                                                        <input type="text" id="map_address" placeholder="输入查找地址" class="form-control"/>
                                                </div>

                                        </div>


                                        <div class="col-md-10  padding0 pull-right">
                                                <div class="col-md-10 thumbnail pull-left  ">
                                                        <div id="map_wraper"  >

                                                        </div>
                                                </div>

                                        </div>
                                            
                                        <div class="col-md-12 margin10" id="fushu_div" 
                                             <empty name="arr">style="display:none"</empty> 
                                             >
                                            
                                            <div class="col-md-2 text_right form_bar" id="fushu_tip">
                                                附属价格 ：
                                            </div>
                                            <div class="col-md-9">
                                                {$empty}
                                                <table class="table table-bordered" id="fushu_table" >
                                                    <thead>
                                                        <tr>
                                                            <th class="fushu_th" style="display:none;"></th>
                                                            <volist name="goodsList" id="vo" >
                                                                <th class="fushu_th delete_{$key}" data-id="delete_{$key}" data-cat="{$vo.catID}">
                                                                    <a href="javascript:void(0);" tabindex="0" class="edit_fushu" data-id="{$vo.goodsID}" >
                                                                        <font id="fushu_name_{$vo.goodsID}"  
                                                                       {$vo['isSale'] == 1 ? '':'style="color:red"'} 
                                                                       >{$vo.goodsName}</font>
                                                                        <input type="hidden" id="fushu_sale_{$vo.goodsID}" value="{$vo.isSale}" />
                                                                        <input type="hidden" id="fushu_limitNum_{$vo.goodsID}" value="{$vo.limitNum}" />
																		<textarea style="display:none" id="fushu_goods_desc_{$vo.goodsID}">{$vo.goods_desc}</textarea>
                                                                    </a>
                                                                </th>
                                                            </volist>
                                                        </tr>
                                                    </thead>
                                                    <tbody>
                                                        <tr>
                                                            <td class="fushu_td" style="display:none;"></td>
                                                            <volist name="goodsList" id="vo" >
                                                                <td class="fushu_td delete_{$key}">

                                                                    <a href="javascript:void(0);" id="fushu_price_{$vo.goodsID}" 
                                                                       class="text-orange edit_price"  data-id="{$vo.goodsID}"
                                                                       title="" data-original-title="编辑价格">
                                                                                            {$vo.goodsPrice}
                                                                    </a>
                                                                </td>
                                                            </volist>
                                                        </tr>
                                                    </tbody>
                                                </table>
                                            </div>

                                        </div>


                                </div>
                                                <input type="hidden" id="x" value="{$arr.x}" />
                                                <input type="hidden" id="y" value="{$arr.y}" />
                                                <input type="hidden" id="thumb" value="{$imgDomain}{$arr.thumb}" />
                                                <input type="hidden" id="headImg" value="{$imgDomain}{$arr.headImg}" />
                                                <input type="hidden" id="province" value="{$arr.province}" />
                                                <input type="hidden" id="district" value="{$arr.district}" />
                                                <input type="hidden" id="city" value="{$arr.city}" />
                                                <input type="hidden" id="shopID" value="{$arr.shopID}" />
                                     

                                </div>
                        </div>

                </div>

			</div>
		</div>
</div>


<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel"> </h4>
            </div>
            <div class="modal-body">
                    <div class="row clearfix">
                        <div class="col-md-12 margin10">
                            <div class="col-md-2 text_right form_bar">
                                名称：
                            </div>
                            <div class="col-md-6">
                                <input id="goodsName" type="text" class="form-control"/>
                            </div>
                            <div class="col-md-1 text_warning text_left form_bar">
                                *
                            </div>
                        </div>
                        <div class="col-md-12 margin10">
                            <div class="col-md-2 text_right form_bar">
                                价格：
                            </div>
                            <div class="col-md-6">
                                <input id="goodsPrice" type="text" class="form-control"/>
                            </div>
                            <div class="col-md-1 text_warning text_left form_bar">
                                *
                            </div>
                        </div>
                        <div class="col-md-12 margin10">
                            <div class="col-md-2 text_right form_bar">
                                限购数量：
                            </div>
                            <div class="col-md-6">
                                <input id="limitNum" value='-1' type="text" class="form-control"/>
                            </div>
                            <div class="col-md-1 text_warning text_left form_bar">
                            *
                            </div>
                             -1为不限购
                        </div>
                        <div class="col-md-12 margin10">
                            <div class="col-md-2 text_right form_bar">
                                    类型：
                            </div>
                            <div class="col-md-6">
                               <select  id="catID" class="form-control">
	                               	<volist name="typeList" id="type" >
	                                   <option value="{$type.catID}" id="catID_{$type.catID}" >{$type.catName}</option>
					</volist>
                                </select>
                            </div>
                            <div class="col-md-1 text_warning text_left form_bar">
                                    *
                            </div>
                    </div>
                        <div class="col-md-12 margin10">
                            <div class="col-md-2 text_right form_bar">
                                是否激活：
                            </div>
                            <div class="btn-group clearfix" data-toggle="buttons">
                                <label class="btn btn-warning btn-sm" id="isSale_label_1">
                                    <input name="isSale" type="radio" id="isSale_1" autocomplete="off" value="1" > ON
                                </label>
                                <label class="btn btn-warning btn-sm" id="isSale_label_1">
                                    <input name="isSale" type="radio" id="isSale_0" autocomplete="off" value="0" > OFF
                                </label>
                            </div>
                        </div>
						<div class="col-md-12 margin10">
                            <div class="col-md-2 text_right form_bar">
                                暂停销售提示：
                            </div>
                            <div class="col-md-4">
                                <textarea id="goods_desc" class="form-control" name="goods_desc"></textarea>
                            </div>
                        </div>
						
                        <input id="goodsID" type="hidden" />

                    </div>

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary" id="save_fushu" >保存</button>
            </div>
        </div>
    </div>
</div>



<include file="Include/script" />
<script type="text/javascript" src="__STATICS__/js/jquery.ui.widget.js"></script>
<script type="text/javascript" src="__STATICS__/js//jquery.iframe-transport.js"></script>
<script type="text/javascript" src="__STATICS__/js/jquery.fileupload.js"></script>
<script type="text/javascript" src="__STATICS__/js/jquery-form.js"></script>
<script type="text/javascript" src="__STATICS__/js/upload_base.js"></script>
<script type="text/javascript" src="__STATICS__/js/area.js"></script>

<script src="__STATICS__/js/admin/hzAjax.js" type="text/javascript"></script>
<script type="text/javascript" src="__STATICS__/js/admin/shopMsg.js"></script>

<script type="text/javascript" src="http://api.map.baidu.com/api?v=1.5&ak=f4tOXtNF8RR1EFO3TlcpBAWO"></script>
<script src="__STATICS__/js/bootstrap-editable.min.js"></script>
<script>
    var headImgUrl = "{:U('CNEPAdmin/Upload/uploadImg/pathType/1')}";
    var statics_url = "__STATICS__";
    var isAdd ; // 是否为添加
    var isAddFushu ; // 是否为添加附属商品
    var myDom; // 当前的dom对象
    
     /*初始化编辑器，展现方式为弹窗*/
    $.fn.editable.defaults.mode = 'placement'; 
    window.ajaxData = {};

    init_edit_price();
    function init_edit_price()
    {

        if(!!$('.edit_price').editable())
        {
            $('.edit_price').editable('destroy');
        }
        $('.edit_price').editable({
            type: 'text',
            pk: 1,
            url: "{:U('CNEPAdmin/Goods/updateGoods')}",
            title: '编辑价格',
            placement:'top',
            validate:function(value){
                /*组装数据*/
                if($.trim(value) == '') return '不能为空！';
                else if(parseInt($.trim(value)) < 0)
                {
                    return '请输入大于或等于0 的数！';
                }
                else if(isNaN($.trim(value)))
                {
                    return '请输入数字！';
                }
                ajaxData.goodsID = $(this).attr('data-id');
                ajaxData.goodsPrice = value;

            },
            ajaxOptions: {
                type: 'post',
                dataType: 'json',
                data:ajaxData,
                beforeSend:function(){
                }
            },
            success: function(response, newValue) {
                if(response.result === 1)
                {
                    swal('操作成功','','success');
                }
                else
                {
                    swal( '操作失败：'+response.desc,'','warning');
                }

            },
            error:function(){
                swal( '连接失败','','warning');
            }
        });
    }

    
    function checkValue() {
        var rt = true;
        var msg = '';

//        var sa = $.trim($("#shopAccount").val());
//        var pw = $.trim($("#shopPassword").val());
//        var rpw = $.trim($("#rePassword").val());
        var sn = $.trim($("#shopName").val());
        var st = parseInt($.trim($("#shopType").val()));
        var sct = $.trim($("#s_county").val());
        var addr = $.trim($("#address").val());
        var allowCard = $(":radio[name='allowCard']:checked").val();
        var isWork = $(":radio[name='isWork']:checked").val();

//        if (sa.length == 0) {
//            rt = false;
//            msg = "账号不能为空";
//            $("#shopAccount").focus();
//        } else if (pw.length == 0) {
//            rt = false;
//            msg = "密码不能为空";
//            $("#shopPassword").focus();
//        } else if (rpw != pw) {
//            rt = false;
//            msg = "前后密码不一致";
//            $("#rePassword").focus();
//        } else 
        if (sn.length == 0) {
            rt = false;
            msg = "商家名称不能为空";
            $("#shopName").focus();
        }
//        else if (sn.length > 12) {
//            rt = false;
//            msg = "商家名称过长";
//            $("#shopName").focus();
//        } 
        else if (isNaN(parseInt(st))) {
            rt = false;
            msg = "请选择商家类型";
            $("#shopType").focus();
        }else if(st == 1 ){
            if($('.addOilList').length > 0){
                var flag = false;
                $('.addOilList').each(function(){
                    var self = $(this),
                        oilNameInput = self.find('.oilNameInput').val().trim(),
                        oilPriceInput = self.find('.oilPriceInput').val().trim();
                    if( oilNameInput == ''){
                        swal('油单价-品名未填写完整','','warning');
                        flag = true;
                        self.find('.oilNameInput').focus();
                         return false;
                    }

                    else if(oilPriceInput == ''){
                        swal('油单价-价格未填写完整','','warning');
                        flag = true;
                        self.find('.oilPriceInput').focus();
                        return false;
                    }
                    else if(!isFloatFixedTwo(oilPriceInput)){
                        swal('油单价-价格必须为两位小数','','warning');
                        flag = true;
                        self.find('.oilPriceInput').focus();
                        return false;
                    }

                });

                if(flag){
                    return false;
                }
            }
        }else if (sct.length == 0 || sct == "市、县级市") {
            rt = false;
            msg = "请选择省市区";
            $("#s_county").focus();
        } else if (addr.length == 0) {
            rt = false;
            msg = "请输入商家地址";
            $("#address").focus();
        } else if(isNaN(parseInt(allowCard))) {
            rt = false;
            msg = "请选择是否可使用汇通卡";
            $(":radio[name='allowCard']").focus();
        } else if(isNaN(parseInt(isWork))) {
            rt = false;
            msg = "请选择是否营业";
            $(":radio[name='isWork']").focus();
        }
        if(!rt) {
             swal(msg,'','warning');
        }
        
        return rt;
    }
    
    // 清空弹出框的内容
    function initAlerDiv() {
        $("#goodsID").val("");
        $("#goodsName").val("");
        $("#goodsPrice").val("");
        $("#isSale_1").attr("checked",false);
        $("#isSale_0").attr("checked",false);
        $("#isSale_1").closest("label").removeClass("active");
        $("#isSale_0").closest("label").removeClass("active");
    }

    /*是否为两位小数*/
    function isFloatFixedTwo(n){
        return   (!isNaN(n)) && n.toString().split('.')[1].length == 2;
    }
    
	$(document).ready(function () {
		/*地址三级联动初始化*/
		_init_area();
                /*菜单展开及高亮*/
                $('.shop').addClass('open');
                $('#shop1').addClass('active');
                        
                upload_img(headImgUrl,'fileupload','pic','headImg','thumb')/*url,file_input标签id,网页上显示所上传的图片的img标签的id,hiden_input标签的id*/
                        
                var province = "{$arr.province}";
                var city = "{$arr.city}";
                var district = "{$arr.district}";
                
                if(province.length > 0) {
                    $('#s_province').val(province);
                    $('#s_province').trigger('change');
                }
                if(city.length > 0) {
                    $('#s_city').val(city);
                    $('#s_city').trigger('change');
                }
                if(district.length > 0) {
                    $('#s_county').val(district);
                    $('#s_county').trigger('change');
                }
                
                $("#shopType").on("change",function() {
                	var shopType = $(this).val();
                	
                	if(parseInt(shopType) == 1) {
                		$("#oil_div").show();
                	} else {
                		$("#oil_div").hide();
                	}
                });
                
                
                $("#save_msg").on("click",function() {
                    if(checkValue()) {
                        var sid = $.trim($("#shopID").val());
                        
                        var data = {};
                        if(sid > 0) {
                            data.shopID = sid;
                            isAdd = false;
                        } else {
                            isAdd = true;
                        }
                        
                        var shopType = parseInt($.trim($("#shopType").val()));

                        if(shopType == 1) {


                            data.oilPriceJson = [];
                            $('.addOilList').each(function(index,item){
                                var self = $(this);
                                data.oilPriceJson[index] = {}
                                data.oilPriceJson[index].name = self.find('.oilNameInput').val().trim();
                                data.oilPriceJson[index].price = self.find('.oilPriceInput').val().trim();
                            });

                        }
                        
//                        data.shopAccount = $.trim($("#shopAccount").val());
//                        data.shopPassword = $.trim($("#shopPassword").val());
//                        data.rePassword = $.trim($("#rePassword").val());
                        data.shopName = $.trim($("#shopName").val());
                        data.shopType = parseInt($.trim($("#shopType").val()));
                        data.province = $.trim($("#s_province").val());
                        data.city = $.trim($("#s_city").val());
                        data.district = $.trim($("#s_county").val());
                        data.address = $.trim($("#address").val());
                        data.desc = $.trim($("#desc").val());
                        data.headImg = $.trim($("#headImg").val());
                        data.thumb = $.trim($("#thumb").val());
                        data.x= $.trim($("#x").val());
                        data.y = $.trim($("#y").val());
                        data.allowCard = $(":radio[name='allowCard']:checked").val();
                        data.isWork = $(":radio[name='isWork']:checked").val();
                    
                        $.ajax({
                            url: "{:U('CNEPAdmin/Shop/saveShop')}",
                            type: "POST",
                            data: data,
                            cache: false
                        }).done(function (msg) {

                            if (msg.result === 1) {
                               swal('操作成功','','success');
                               if(isAdd) {
                                   $("#shopID").val(msg.desc);
                                   $("#fushu_div").show();
                               }
                            } else {
                               swal('操作失败:'+msg.desc,'','warning');
                            }

                        }).error(function (ex) {
                            swal('操作失败','','error');
                        });
                        
                    } else {
                        return false;
                    }
                });
                
                // 弹出添加附属商品窗口
                $("#add_fushu").on("click",function() {
                    initAlerDiv(); // 清空弹出框
                    
                    $("#myModalLabel").html("添加附属商品");
                    $('#myModal').modal(); // 跳出弹窗
                });
                
                edit_popover();

                function edit_popover(){
                    $('.edit_fushu').popover({
                        trigger:'click',
                        width:200,
                        html: true,
                        content: '<div class="clearfix spec_button_wraper"><a href="javascript:void(0);" class="btn btn-sm btn-danger pull-left margin10 delete_tar">删除</a>' +
                        '<a href="javascript:void(0);" class="btn btn-info btn-sm pull-right margin10 edit_fushu_tar">编辑</a></div>' +
                        '',
                        placement:'top'
                    });
                }
        




        /*删除*/
        $('#fushu_table').delegate('.delete_tar','click',function(){
                var self = $(this);
            var jdata = {};
            jdata.goodsID = $(this).closest('.fushu_th').find('.edit_fushu').attr('data-id');

            swal({   title: "您确定吗?",
                        text: "您将进行删除操作！",
                        type: "warning",
                        showCancelButton: true,
                        confirmButtonColor: "#DD6B55",
                        confirmButtonText: "是的，删除",
                        cancelButtonText: "放弃",
                        closeOnConfirm: false
                    },
                    function (isConfirm) {
                        if (isConfirm) {
                            swal('正在提交....');
                            $.ajax({
                                url: "{:U('CNEPAdmin/Goods/deleteGoods')}",
                                type: "POST",
                                data: jdata,
                                cache: false
                            }).done(function (msg) {

                                if (msg.result === 1) {
                                    $('.'+self.closest('th').attr('data-id')).each(function(){
                                        $(this).remove();
                                    });
                                    swal('操作成功','','success');
                                } else {
                                    swal('操作失败:'+msg.desc,'','warning');
                                }

                            }).error(function (ex) {
                                swal('操作失败','','warning');
                            });
                        }

                    });

        });



                // 弹出窗口以编辑附属商品
                $("#fushu_table").delegate('.edit_fushu_tar',"click",function(e) {
                    initAlerDiv();
                    var self = $(this).closest('th').find('.edit_fushu');
                    var goodsID = self.attr("data-id");
                    var goodsName = $.trim($("#fushu_name_"+goodsID).html());
                    var goodsPrice = $.trim($("#fushu_price_"+goodsID).html());
                    var catID = $(this).closest('th').attr("data-cat");
                    var isSale = $("#fushu_sale_"+goodsID).val();
                    var limitNum = $("#fushu_limitNum_"+goodsID).val();
					var goods_desc = $("#fushu_goods_desc_"+goodsID).val();
                    
                    myDom = $(this).closest('th');
                                        
                    $("#goodsID").val(goodsID);
                    $("#goodsName").val(goodsName);
                    $("#goodsPrice").val(goodsPrice);
                    $("#limitNum").val(limitNum);
                    $("#catID_"+catID).attr("selected",true);
                    $("#isSale_"+isSale).attr("checked",true);
                    $("#isSale_"+isSale).closest('label').addClass('active');
					$("#goods_desc").val(goods_desc);
                    
                    $("#myModalLabel").html("编辑附属商品");
                    $('#myModal').modal(); // 跳出弹窗
                });
                
                // 添加附属商品
                $("#save_fushu").on("click",function() {
                    var rt = true;
                    var msg = '';
                    
                    var goodsName = $.trim($("#goodsName").val());
                    var goodsPrice = parseFloat($("#goodsPrice").val());
                    var catID = parseInt($("#catID").val());
                    var isSale = parseInt($(":radio[name='isSale']:checked").val());
					var isSale = parseInt($(":radio[name='isSale']:checked").val());
                    var goods_desc = $("#goods_desc").val();
					var goodsID = $("#goodsID").val();
                    
//                                        alert("gname:"+goodsName+",gprice:"+goodsPrice+",sale:"+isSale);
                                        
                    if(goodsName.length == 0) {
                        rt = false;
                        msg = "名称不能为空";
                        $("#goodsName").focus();
                    }else if(isNaN(goodsPrice)) {
                        rt = false;
                        msg = "请输入正确的价格";
                        $("#goodsPrice").focus();
                    }else if(isNaN(isSale)) {
                        rt = false;
                        msg = "请选择是否激活销售";
                        $("#isSale_1").focus();
                    }
                    if(!rt) {
                        swal(msg,'','warning');
                        return false;
                    }
                    var limitNum =  $("#limitNum").val();
                    if(limitNum <= 0 || isNaN(parseInt(limitNum))) {
                        limitNum = -1;
                    }
                    var jdata = {};
                    if(goodsID > 0) {
                        jdata.goodsID = goodsID;
                        isAddFushu = false;
                    } else {
                        isAddFushu = true;
                    }
                    jdata.shopID = $("#shopID").val();
                    jdata.goodsName = goodsName;
                    jdata.goodsPrice = goodsPrice;
                    jdata.catID = catID;
                    jdata.isSale = isSale;
                    jdata.limitNum = limitNum;
					jdata.goods_desc = goods_desc;
                    
                   //alert(goodsName);
                    
                    swal('正确保存');
                    
                    $.ajax({
                        url: "{:U('CNEPAdmin/Goods/saveGoods')}",
                        type: "POST",
                        data: jdata,
                        cache: false
                    }).done(function (msg) {

                        if (msg.result === 1) {
                            var isSaleStyle = isSale == 1 ? "":"style=\"color:red\"";

//                            alert("saleStyle:"+isSaleStyle+","+msg.desc);
                            
                            if(isAddFushu) { // 添加
                                 // 追加到附属商品表格后
                                var thLength = $(".fushu_th").length - 1;
                                var thStr = "<th class=\"fushu_th delete_"+thLength+"\" data-id='delete_"+thLength+"'  data-cat='"+catID+"' ><a href=\"javascript:void(0);\" class=\"edit_fushu\" data-id=\"" + msg.desc + "\" "+
                                                " > " + " <font id=\"fushu_name_" + msg.desc + "\" " + isSaleStyle + " >" + goodsName + "</font> " +
                                                 " <input type=\"hidden\" id=\"fushu_sale_" + msg.desc + "\" value=\"" + isSale + "\" /><input type=\"hidden\" id=\"fushu_limitNum_" + msg.desc + "\" value=\"" + limitNum + "\" /><textarea style=\"display:none\" id=\"fushu_goods_desc_" + msg.desc + "\">"  + goods_desc + "</textarea></a></th>";
                                        
                                var tdStr= "<td class=\"fushu_td delete_"+thLength+"\"><a href=\"javascript:void(0);\" id=\"fushu_price_" + msg.desc + "\" "+
                                        " class=\"text-orange edit_price\"  data-id=\"" + msg.desc + "\" data-original-title=\"编辑价格\" >"+goodsPrice+"</a></td>";
                                
                                $("#fushu_table .fushu_th:last").after(thStr);
                                $("#fushu_table .fushu_td:last").after(tdStr);

                                $("#goodsID").val(msg.desc); // 新添加的id
                                 edit_popover();
                                
                            } else { // 编辑
                                // 修改表格中的显示
                                if(isSale == 1) {
                                    $("#fushu_name_"+goodsID).css("color",'');
                                } else {
                                    $("#fushu_name_"+goodsID).css("color",'red');
                                }
                                
                                $("#fushu_name_"+goodsID).html(goodsName);
                                $("#fushu_price_"+goodsID).html(goodsPrice);
                                $("#fushu_sale_"+goodsID).val(isSale);
                                $("#fushu_limitNum_"+goodsID).val(limitNum);
								$("#fushu_goods_desc_"+goodsID).val(goods_desc);
                                myDom.attr("data-cat",catID);
                            }

                            init_edit_price();
                           
                           swal('操作成功','','success');
                           $('#myModal').modal('hide'); // 关闭弹出框
                        } else {
                           swal('操作失败:'+msg.desc,'','warning');
                        }

                    }).error(function (ex) {
                        swal('操作失败','','warning');
                    });
                });
                
                
		//初始化百度地图

		var map = new BMap.Map("map_wraper");                        // 创建Map实例
		map.centerAndZoom("广州", 12);     // 初始化地图,设置中心点坐标和地图级别
		map.addControl(new BMap.NavigationControl());               // 添加平移缩放控件
		map.enableScrollWheelZoom();                            //启用滚轮放大缩小

		//初始化地址查找框
		$('#map_address').focus(function () {
			if ($(this).val() == '输入查找地址') {
				$(this).val('');
				$(this).css("color", "#000000");
			}
		});

		$('#map_address').blur(function () {
			if ($(this).val() == "") {
				$(this).val('输入查找地址');
				$(this).css("color", "#999999");
			}
		});

		//建立一个自动完成的对象
		var ac = new BMap.Autocomplete(
				{"input": "map_address"
					, "location": map
				});
		var myValue;
		//鼠标点击下拉列表后的事件
		ac.addEventListener("onconfirm", function (e) {
			var _value = e.item.value;
			myValue = _value.province + _value.city + _value.district + _value.street + _value.business;
			setPlace();
		});

		//定位函数
		function setPlace() {
			map.clearOverlays();    //清除地图上所有覆盖物
			function myFun() {
				var pp = local.getResults().getPoi(0).point;    //获取第一个智能搜索的结果
				map.centerAndZoom(pp, 18);
				map.addOverlay(new BMap.Marker(pp));    //添加标注
				$("#txt_lng").val(pp.lng);
				$("#txt_lat").val(pp.lat);
				$("#x").val(pp.lng);
				$("#y").val(pp.lat);

			}
			//智能搜索
			var local = new BMap.LocalSearch(map, {
				onSearchComplete: myFun
			});
			local.search(myValue);
		}
		map.addEventListener("click", function (e) {
			map.clearOverlays();    //清除地图上所有覆盖物
			//经度 e.point.lng
			$("#txt_lng").val(e.point.lng);
			$("#x").val(e.point.lng);
			//纬度 e.point.lat
			$("#txt_lat").val(e.point.lat);
			$("#y").val(e.point.lat);
			map.addOverlay(new BMap.Marker(e.point));
		});

	});
</script>
<script src="__STATICS__/js/admin/oilAdd.js">

</script>
</body>
</html>